package com.yupi.oj.controller;

import com.yupi.oj.common.BaseResponse;
import com.yupi.oj.common.ResultUtils;
import com.yupi.oj.model.dto.questionSubmitLog.QuestionSubmitLogAddRequest;
import com.yupi.oj.model.dto.questionSubmitLog.QuestionSubmitLogSearchRequest;
import com.yupi.oj.model.vo.QuestionSubmitLogVO;
import com.yupi.oj.service.QuestionSubmitLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author yanghaifeng
 * @date 2024/4/11 15:39
 */
@RequestMapping("/questionSubmitLog")
@RestController
@Api(tags = "做题提交记录接口")
public class QuestionSubmitLogController {

    @Autowired
    private QuestionSubmitLogService service;

    @ApiOperation("创建做题提交记录")
    @PostMapping("/add")
    public BaseResponse<Long> add(@RequestBody QuestionSubmitLogAddRequest questionSubmitLogAddRequest, HttpServletRequest request) {
        return ResultUtils.success(service.add(questionSubmitLogAddRequest, request));
    }

    @ApiOperation("删除做题提交记录")
    @GetMapping("/delete")
    public BaseResponse<Boolean> delete(@RequestParam("id") Long id, HttpServletRequest request) {
        return ResultUtils.success(service.delete(id, request));
    }

    @ApiOperation("查询做题提交记录")
    @GetMapping("/queryById")
    public BaseResponse<QuestionSubmitLogVO> queryById(@RequestParam("id") Long id) {
        return ResultUtils.success(service.queryById(id));
    }

    @ApiOperation("列表查询")
    @PostMapping("/queryList")
    public BaseResponse<List<QuestionSubmitLogVO>> queryList(@RequestBody QuestionSubmitLogSearchRequest questionSubmitLogSearchRequest) {
        return ResultUtils.success(service.queryList(questionSubmitLogSearchRequest));
    }

    @ApiOperation("根据题目 Id 查询做题记录列表")
    @GetMapping("/queryListByQuestionId")
    public BaseResponse<List<QuestionSubmitLogVO>> queryListByQuestionId(@RequestParam("questionId") Long questionId) {
        return ResultUtils.success(service.queryListByQuestionId(questionId));
    }
}
